package concurrent;

import java.util.Comparator;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * @author Summerday
 */
public class PriorityBlockingQueueDemo {

    public static void main (String[] args) throws InterruptedException {


        PriorityBlockingQueue<Person> q = new PriorityBlockingQueue<>(10, new Comparator<Person>() {
            @Override
            public int compare (Person o1, Person o2) {
                return o1.age - o2.age;
            }

            @Override
            public boolean equals (Object obj) {
                return false;
            }
        });

        q.add(new Person(3));
        q.add(new Person(5));
        q.add(new Person(1));
        q.add(new Person(2));
        System.out.println(q);
    }
}


class Person {
    int age;

    Person (int age) {
        this.age = age;
    }

    public int getAge () {
        return age;
    }

    public void setAge (int age) {
        this.age = age;
    }
}
